﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YouHP.Model
{
    public class TreatmentSearchCondition
    {
        public string TreatmentName { get; set;}
        public string DiseaseName { get; set; }
        public int DiseaseId { get; set; }
        public string FirstLetter { get; set; }

        public TreatmentSearchCondition()
        {
            TreatmentName = DiseaseName = FirstLetter = string.Empty;
            DiseaseId = -1;
        }

        public string ToSqlConditonString()
        {
            string sql = string.Empty;
            bool firstCond = true;

            if (TreatmentName.Length > 0)
            {
                sql = string.Format(" ([Treatment].[TreatmentName] like '%{0}%' or "
                    + " [Treatment].[GeneralName] like '%{0}%') ", TreatmentName);
                firstCond = false;
            }
            
            if (DiseaseId > 0)
            {
                if (!firstCond)
                {
                    sql += " and ";
                }
                sql += string.Format(" [DiseaseTreatment].[DiseaseId] = {0} ", DiseaseId);
            }

            //如果有首字符作为条件,则丢弃掉其它条件
            if (FirstLetter.Length > 0)
            {
                sql = string.Format(" [Treatment].[firstsymbolofname] like '{0}%' ", FirstLetter);
            }

            return sql;
        }
    }
}
